import { VuexModule, Module, Mutation, Action, getModule } from 'vuex-module-decorators'
import store from '@/store'

export interface IPageSize {
  commonTablePageSize: number
  dialopTablePageSize: number
}

@Module({ dynamic: true, store, name: 'pageSize' })
class PageSize extends VuexModule implements IPageSize {
  commonTablePageSize: number = parseInt(localStorage.getItem('commonTablePageSize') || "10") || 10;
  dialopTablePageSize: number = parseInt(localStorage.getItem('dialopTablePageSize') || "10") || 10;

  @Mutation
  private CHANGE_COMMON_TABLE_PAGE_SIZE(size: number) {
    this.commonTablePageSize = size;
    localStorage.setItem('commonTablePageSize', size.toString());
  }

  @Mutation
  private CHANGE_DIALOP_TABLE_PAGE_SIZE(size: number) {
    this.dialopTablePageSize = size;
    localStorage.setItem('dialopTablePageSize', size.toString());
  }

  @Action
  public changeCommonTablePageSize(size: number) {
    this.CHANGE_COMMON_TABLE_PAGE_SIZE(size);
  }

  @Action
  changeDialopTablePageSize(size: number) {
    this.CHANGE_DIALOP_TABLE_PAGE_SIZE(size);
  }
}

export const PageSizeModule = getModule(PageSize)
